/*--------------------------------------------------------------------
 * File name: change_arr_length.h
 * Author: 刘长达      Version:   1.0     Date:12.06
 * Description: 完成数组长度的更改
 * Contents: 更改数组函数
 *--------------------------------------------------------------------*/

/*--------------------------------------------------------------------
 *                          文件更新和维护记录
 * Author:	刘长达
 * Date:	2019.12.6
 * Contents: 完成改变数组长度函数
 *
 *--------------------------------------------------------------------*/
#ifndef CHANGE_ARR_LENGTH
#define CHANGE_ARR_LENGTH
#include<stdexcept>
#include<algorithm>
template<typename T>
void changeLength1D(T *&a,int oldLength, int newLength)
{
    if(newLength < 0)
        throw std::runtime_error("New length must be >=0");

    T* temp = new T[newLength];
    int number = std::min(oldLength, newLength);
    //copy( from_vector.begin(), from_vector.end(), to_vector.begin())
    std::copy(a, a+number, temp);
    delete [] a;
    a = temp;
}
#endif // CHANGE_ARR_LENGTH

